package simpletestbed.core;

import java.io.File;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.UnknownHostException;

public class JVMHelper {
	
	public static void addClassPath(String s) throws Exception  {
		File f = new File(s);
		URL u = f.toURI().toURL();
		URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
		Class urlClass = URLClassLoader.class;
		Method method = urlClass.getDeclaredMethod("addURL", new Class[]{URL.class});
		method.setAccessible(true);
		method.invoke(urlClassLoader, new Object[]{u});
	}
	
	public static String getHostname() throws UnknownHostException {
		InetAddress localMachine = InetAddress.getLocalHost();	
		return localMachine.getHostName();
	}
	
}
